module Scene {
	/**
	 * 游戏准备场景 ---郭启航
	 * */
	export class ScenePrepare extends egret.DisplayObjectContainer {
		public constructor() {
			super();
			this.Prepare_UI = new Fighter.PrepareUI();
			this.BuyEnemy_UI = new Fighter.BuyEnemyUI();
			this.BuyGuard_UI = new Fighter.BuyGuardUI();
			//this.BuyWingman_UI = new fighter.BuyWingmanUI();
			this.ready_UI = new Fighter.ReadyUI();
			//this.Invest_UI = new fighter.InvestUI();
			//this.Update_UI = new fighter.UpdateUI();

			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
			this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removeFromStage, this);
		}


		/**准备场景结束 */
		public EndPrepare: boolean = false;

		/**游戏准备页面*/
		public Prepare_UI: Fighter.PrepareUI;
		/**购买敌机页面*/
		private BuyEnemy_UI: Fighter.BuyEnemyUI;
		/**购买僚机页面*/
		private BuyGuard_UI: Fighter.BuyGuardUI;
		/**准备完成页面*/
		private ready_UI: Fighter.ReadyUI;


		/**场景添加到舞台 */
		private addToStage(evt: egret.Event) {
			this.addChild(this.Prepare_UI);
			Fighter.PrepareUI.isReadyShow = false;
			this.EndPrepare = false;
			this.addEventListener(egret.Event.ENTER_FRAME, this.updateGameView, this);
			GameUtil.PlayerMessage.instance.sendEnemy = [];
			GameUtil.PlayerMessage.instance.sendEnemy.splice(0);
			//添加每波的默认飞机
			for (let i = 0; i < GameUtil.PlayerMessage.instance.PlaneNum; i++) {
				GameUtil.PlayerMessage.instance.sendEnemy.push(EnemyType["feiji0_png"]);
			}
		}

		/**场景离开舞台 */
		private removeFromStage(evt: egret.Event) {
			this.removeEventListener(egret.Event.ENTER_FRAME, this.updateGameView, this);
			this.removeChildren();
		}

		/**每帧检测 */
		private updateGameView(evt: egret.Event) {
			/**添加购买敌人页面*/
			if (this.Prepare_UI.Is_BuyEnemy) {
				this.Prepare_UI.Is_BuyEnemy = false;
				this.removeChild(this.Prepare_UI);
				this.addChild(this.BuyEnemy_UI);
			}
			/**购买敌人页面返回*/
			if (this.BuyEnemy_UI.Is_back) {
				this.BuyEnemy_UI.Is_back = false;
				this.removeChild(this.BuyEnemy_UI);
				this.addChild(this.Prepare_UI);
			}

			/**添加购买僚机页面*/
			if (this.Prepare_UI.Is_BuyGuard) {
				this.Prepare_UI.Is_BuyGuard = false;
				this.removeChild(this.Prepare_UI);
				this.addChild(this.BuyGuard_UI);
			}
			/**添加购买僚机返回*/
			if (this.BuyGuard_UI.Is_back) {
				this.BuyGuard_UI.Is_back = false;
				this.removeChild(this.BuyGuard_UI);
				this.addChild(this.Prepare_UI);
			}

			/**添加准备完成页面*/
			if (this.Prepare_UI.Is_Reday) {
				this.Prepare_UI.Is_Reday = false;
				this.removeChild(this.Prepare_UI);
				this.addChild(this.ready_UI);
			}
			/**准备完成页面返回*/
			if (this.ready_UI.Is_back) {

				this.ready_UI.Is_back = false;
				this.removeChild(this.ready_UI)
				this.addChild(this.Prepare_UI)
			}

			/**添加游戏内容*/
			if (this.ready_UI.Is_startgame) {
				this.ready_UI.Is_startgame = false;
				this.removeChild(this.ready_UI);
				this.EndPrepare = true;
			}
		}
	}
}